module.exports = (sequelize, DataTypes) => {
  const LessonTag = sequelize.define('LessonTag', {
    lessonId: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      field: 'lesson_id',
      comment: '课程ID'
    },
    tagId: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      field: 'tag_id',
      comment: '标签ID'
    }
  }, {
    tableName: 'lesson_tags',
    underscored: true,
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: false,
    comment: '课程标签关联表',
    indexes: [
      {
        fields: ['tag_id']
      }
    ]
  });

  LessonTag.associate = (models) => {
    LessonTag.belongsTo(models.Lesson, {
      foreignKey: 'lessonId',
      onDelete: 'CASCADE'
    });
    
    LessonTag.belongsTo(models.Tag, {
      foreignKey: 'tagId',
      onDelete: 'CASCADE'
    });
  };

  return LessonTag;
}; 